package o;

import java.io.IOException;

public final class ags {
    private long ʻ = -9223372036854775807L;
    private long ʽ = -9223372036854775807L;
    private boolean ˊ;
    private final anc ˋ = new anc();
    private boolean ˎ;
    private final anq ˏ = new anq(0);
    private boolean ॱ;
    private long ᐝ = -9223372036854775807L;

    public boolean ˋ() {
        return this.ˊ;
    }

    public int ˏ(adv o_adv, adz o_adz, int i) throws IOException, InterruptedException {
        if (i <= 0) {
            return ˎ(o_adv);
        }
        if (!this.ˎ) {
            return ˋ(o_adv, o_adz, i);
        }
        if (this.ᐝ == -9223372036854775807L) {
            return ˎ(o_adv);
        }
        if (!this.ॱ) {
            return ॱ(o_adv, o_adz, i);
        }
        if (this.ʽ == -9223372036854775807L) {
            return ˎ(o_adv);
        }
        this.ʻ = this.ˏ.ˏ(this.ᐝ) - this.ˏ.ˏ(this.ʽ);
        return ˎ(o_adv);
    }

    public long ˏ() {
        return this.ʻ;
    }

    public anq ॱ() {
        return this.ˏ;
    }

    private int ˎ(adv o_adv) {
        this.ˋ.ˋ(anr.ʽ);
        this.ˊ = true;
        o_adv.ˏ();
        return 0;
    }

    private int ॱ(adv o_adv, adz o_adz, int i) throws IOException, InterruptedException {
        int min = (int) Math.min(112800, o_adv.ॱ());
        if (o_adv.ˊ() != ((long) null)) {
            o_adz.ˊ = (long) null;
            return 1;
        }
        this.ˋ.ˏ(min);
        o_adv.ˏ();
        o_adv.ˎ(this.ˋ.ˏ, 0, min);
        this.ʽ = ॱ(this.ˋ, i);
        this.ॱ = true;
        return 0;
    }

    private long ॱ(anc o_anc, int i) {
        int ˋ = o_anc.ˋ();
        int ॱ = o_anc.ॱ();
        for (int i2 = ˋ; i2 < ॱ; i2++) {
            if (o_anc.ˏ[i2] == (byte) 71) {
                long ˊ = aha.ˊ(o_anc, i2, i);
                if (ˊ != -9223372036854775807L) {
                    return ˊ;
                }
            }
        }
        return -9223372036854775807L;
    }

    private int ˋ(adv o_adv, adz o_adz, int i) throws IOException, InterruptedException {
        long ॱ = o_adv.ॱ();
        int min = (int) Math.min(112800, ॱ);
        ॱ -= (long) min;
        if (o_adv.ˊ() != ॱ) {
            o_adz.ˊ = ॱ;
            return 1;
        }
        this.ˋ.ˏ(min);
        o_adv.ˏ();
        o_adv.ˎ(this.ˋ.ˏ, 0, min);
        this.ᐝ = ˋ(this.ˋ, i);
        this.ˎ = true;
        return 0;
    }

    private long ˋ(anc o_anc, int i) {
        int ˋ = o_anc.ˋ();
        for (int ॱ = o_anc.ॱ() - 1; ॱ >= ˋ; ॱ--) {
            if (o_anc.ˏ[ॱ] == (byte) 71) {
                long ˊ = aha.ˊ(o_anc, ॱ, i);
                if (ˊ != -9223372036854775807L) {
                    return ˊ;
                }
            }
        }
        return -9223372036854775807L;
    }
}
